﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
//using System.Linq;
using System.Text;
//using System.Threading.Tasks;
using TRicheControl.DefaultControlStyles.Helper;
using TRicheControl.Interface.ControlStyle;

namespace TRicheControl.DefaultControlStyles
{
    public class VScrollBarStyle : IVScrollBarStyle
    {
        private SolidBrush mBarBackGroundBrush;
        private SolidBrush mUpArrowBrush;
        private SolidBrush mSliderBrush;
        private SolidBrush mDowArrowBrush;

        public VScrollBarStyle()
        {
            mBarBackGroundBrush = new SolidBrush(Color.DarkGray);
            mSliderBrush = new SolidBrush(Color.FromArgb(125, Color.Black));
            mUpArrowBrush = new SolidBrush(Color.FromArgb(125, Color.Black));
            mDowArrowBrush = new SolidBrush(Color.FromArgb(125, Color.Black));
        }

        public void DrawBarBackGround(System.Drawing.Graphics g, System.Drawing.Rectangle rect)
        {
            g.FillRectangle(mBarBackGroundBrush, rect);
        }

        public void DrawSlider(System.Drawing.Graphics g, System.Drawing.Rectangle rect)
        {
            g.FillRectangle(mSliderBrush, rect);
        }

        public void DrawMouseEnterSlider(System.Drawing.Graphics g, System.Drawing.Rectangle rect)
        {
            
        }

        public void DrawMouseDownSlider(System.Drawing.Graphics g, System.Drawing.Rectangle rect)
        {
            
        }

        public void DrawUpArrow(System.Drawing.Graphics g, System.Drawing.Rectangle rect)
        {
            DrawHelper.SetGraphics(g);
            g.FillRectangle(mUpArrowBrush, rect);
            DrawArrow(g, rect, Color.White, true);
        }

        public void DrawMouseEnterUpArrow(System.Drawing.Graphics g, System.Drawing.Rectangle rect)
        {
            //g.FillRectangle(new SolidBrush(Color.FromArgb(100, Color.Black)), rect);
        }

        public void DrawMouseDownUpArrow(System.Drawing.Graphics g, System.Drawing.Rectangle rect)
        {
            //g.FillRectangle(new SolidBrush(Color.FromArgb(125, Color.Black)), rect);
        }

        public void DrawDownArrow(System.Drawing.Graphics g, System.Drawing.Rectangle rect)
        {
            DrawHelper.SetGraphics(g);
            g.FillRectangle(mDowArrowBrush, rect);
            DrawArrow(g, rect, Color.White, false);
        }

        public void DrawMouseEnterDownArrow(System.Drawing.Graphics g, System.Drawing.Rectangle rect)
        {
            
        }

        public void DrawMouseDownDownArrow(System.Drawing.Graphics g, System.Drawing.Rectangle rect)
        {
            
        }

        private int mArrowWidth = 2;

        private void DrawArrow(Graphics g, Rectangle rect, Color color, bool isUp)
        {
            GraphicsPath path = new GraphicsPath();
            int flag = rect.Height / 6;
            Point connPoint = Point.Empty;
            if (isUp)
            {
                connPoint = new Point(rect.Width / 2, rect.Y + mArrowWidth + flag);
                path.AddLine(new Point(mArrowWidth, (rect.Height / 2) + flag), connPoint);
                path.AddLine(new Point(rect.Width - mArrowWidth, (rect.Height / 2) + flag), connPoint);
            }
            else
            {
                connPoint = new Point(rect.Width / 2, rect.Y + (rect.Height - mArrowWidth - flag));
                path.AddLine(new Point(mArrowWidth, rect.Y + (flag + mArrowWidth)), connPoint);
                path.AddLine(new Point(rect.Width - mArrowWidth, rect.Y + (flag + mArrowWidth)), connPoint);
            }
            g.DrawPath(new Pen(color, mArrowWidth), path);
        }
    }
}
